//package com.xingda.packing.minitor.controller;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.xingda.packing.annotation.LimitRequest;
//import com.xingda.packing.annotation.OpLog;
//import com.xingda.packing.common.OperationConstant;
//import com.xingda.packing.common.R;
//import com.xingda.packing.config.ThreadLocalConfig;
//import com.xingda.packing.domain.ShuntProductionLine;
//import com.xingda.packing.enums.WorkAreaType;
//import com.xingda.packing.minitor.dto.CleanShuntDto;
//import com.xingda.packing.minitor.dto.CleanShuntWheelDto;
//import com.xingda.packing.minitor.dto.UserInfo;
//import com.xingda.packing.minitor.entity.PkShuntArea;
//import com.xingda.packing.minitor.entity.PkShuntWheel;
//import com.xingda.packing.minitor.mapper.PkShuntAreaMapper;
//import com.xingda.packing.minitor.mapper.PkShuntWheelMapper;
//import com.xingda.packing.minitor.service.IpkLogService;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@RestController
//@RequestMapping("/api/shunt")
//public class ShuntAreaController {
//    @Resource
//    private ShuntProductionLine shuntProductionLine;
//    @Resource
//    private IpkLogService ipkLogService;
//    @Resource
//    private ThreadLocalConfig threadLocalConfig;
//    @Resource
//    private PkShuntAreaMapper pkShuntAreaMapper;
//    @Resource
//    private PkShuntWheelMapper pkShuntWheelMapper;
//
//
//    @GetMapping("/show/{area}")
//    public R showInfo(@PathVariable int area) {
//        List<List<PkShuntWheel>> pkWheels = new ArrayList<>();
//        LambdaQueryWrapper<PkShuntArea> pkShuntAreaLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        pkShuntAreaLambdaQueryWrapper.eq(PkShuntArea::getArea, area);
//        pkShuntAreaLambdaQueryWrapper.eq(PkShuntArea::getTag, 1);
//        List<PkShuntArea> pkShuntAreas = pkShuntAreaMapper.selectList(pkShuntAreaLambdaQueryWrapper);
//        if (!pkShuntAreas.isEmpty()) {
//            List<Integer> collect1 = pkShuntAreas.stream().filter(pkShuntArea -> pkShuntArea.getLocation() == 1).map(PkShuntArea::getWheelId).collect(Collectors.toList());
//            List<Integer> collect2 = pkShuntAreas.stream().filter(pkShuntArea -> pkShuntArea.getLocation() == 2).map(PkShuntArea::getWheelId).collect(Collectors.toList());
//            LambdaQueryWrapper<PkShuntWheel> pkShuntWheelLambdaQueryWrapper1 = new LambdaQueryWrapper<>();
//            pkShuntWheelLambdaQueryWrapper1.in(PkShuntWheel::getId, collect1);
//            List<PkShuntWheel> pkShuntWheels1 = pkShuntWheelMapper.selectList(pkShuntWheelLambdaQueryWrapper1);
//            LambdaQueryWrapper<PkShuntWheel> pkShuntWheelLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
//            pkShuntWheelLambdaQueryWrapper2.in(PkShuntWheel::getId, collect2);
//            List<PkShuntWheel> pkShuntWheels2 = pkShuntWheelMapper.selectList(pkShuntWheelLambdaQueryWrapper2);
//            pkWheels.add(pkShuntWheels1);
//            pkWheels.add(pkShuntWheels2);
//        }
//        return R.ok().put("data", pkWheels);
//    }
//
//    @LimitRequest(count = 1)
//    @OpLog(username = "#cleanShuntDto.username",
//            corp = "#cleanShuntDto.corp",
//            veri = "#cleanShuntDto.veri",
//            opItem = OperationConstant.REMOVE_ALL_SHUNTAREA_WHEEL,
//            param = "#cleanShuntDto.area")
//    @PostMapping("/cleanShuntArea")
//    public R cleanShuntArea(@RequestBody CleanShuntDto cleanShuntDto) {
//        try {
//            shuntProductionLine.getShuntArea().cleanAllToSql(cleanShuntDto.getArea(),cleanShuntDto.getLocation());
//            UserInfo userInfo = threadLocalConfig.get();
//            userInfo.setOperation(OperationConstant.REMOVE_ALL_SHUNTAREA_WHEEL + ",区域" + WorkAreaType.getByID(cleanShuntDto.getArea()).getTypeName());
//            ipkLogService.saveLog(userInfo);
//            return R.ok();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return R.error();
//    }
//
//    @LimitRequest(count = 1)
//    @OpLog(username = "#cleanShuntWheelDto.username",
//            corp = "#cleanShuntWheelDto.corp",
//            veri = "#cleanShuntWheelDto.veri",
//            opItem = OperationConstant.REMOVE_SHUNT_WHEEL,
//            param = "#cleanShuntWheelDto.area")
//    @PostMapping("/cleanShuntWheel")
//    public R cleanShuntWheel(@RequestBody CleanShuntWheelDto cleanShuntWheelDto) {
//        try {
//            LambdaQueryWrapper<PkShuntArea> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//            lambdaQueryWrapper.eq(PkShuntArea::getArea, cleanShuntWheelDto.getArea());
//            lambdaQueryWrapper.eq(PkShuntArea::getBarCode, cleanShuntWheelDto.getBarCode());
//            lambdaQueryWrapper.eq(PkShuntArea::getLocation, cleanShuntWheelDto.getLocation());
//            PkShuntArea pkShuntArea = pkShuntAreaMapper.selectOne(lambdaQueryWrapper);
//            pkShuntArea.setTag(0);
//            pkShuntAreaMapper.updateById(pkShuntArea);
//            UserInfo userInfo = threadLocalConfig.get();
//            userInfo.setOperation(OperationConstant.REMOVE_SHUNT_WHEEL + ",区域" + WorkAreaType.getByID(cleanShuntWheelDto.getArea()).getTypeName());
//            ipkLogService.saveLog(userInfo);
//            return R.ok();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return R.error();
//    }
//}
